package com.itheima.reggie.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * 邮件发送工具类
 */
@Service
public class SendMailUtils{


    @Autowired
    private  JavaMailSender javaMailSender;
    //发送人
    String from = "yhans0923@qq.com";

    //正文
    String context1 = "您好，你的验证码为";
    String context2 = ",该验证码仅在5分钟内有效，请勿泄露于他人！祝您生活愉快";


    public  void sendMail(String sendToEmail,String code) {

        SimpleMailMessage message = new SimpleMailMessage();

        message.setFrom(from+"(【瑞吉外卖】)");
        //拼接邮箱后缀
        sendToEmail += "@qq.com";
        message.setTo(sendToEmail);

        //标题
        String subject="尊敬的QQ用户"+sendToEmail.substring(0,10);
        message.setSubject(subject);

        //邮件内容
        String context=context1+code+context2;
        message.setText(context);

        javaMailSender.send(message);
    }
}
